#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Solution {
public:
    int maxValue(int n, int index, int maxSum) {
        int T = maxSum - n;
        int result = 1;
        int left = 1;
        int right = T;
        while(left<=right){
            //在index上放置i，其余位置还有T-i块
            //等于是在求等差数列（递减）
            //左边还有index-0块
            long long i = (left+right)/2;
            int leftnum;
            if(index>=i-1){
                //左边最多需要
                if(i-1>0){
                    leftnum = (i-1)+0.5*(i-1)*(i-2);
                }
                else{
                    leftnum = 0;
                }
            }
            else{
                if(i-1>0){
                    leftnum = 0.5*index*((i-1-index+1+i-1));
                }   
                else{
                    leftnum = 0;
                }
            }

            //右边有n-index-1块
            int rightnum;
            if(n-index-1>=i-1){
                //右边最少需要
                if(i-1>0){
                    rightnum = (i-1)+0.5*(i-1)*(i-2);
                }
                else{
                    rightnum = 0;
                }
            }
            else{
                if(i-1>0){
                    rightnum = 0.5*(n-index-1)*((i-1-(n-index-2)+i-1));
                }   
                else{
                    rightnum = 0;
                }
            }
            long long A = rightnum+leftnum;
            if(A<=T-i){
                result = max(result,int(i+1));
                left = i+1;
            }
            else{
                right = i-1;
            }

        }
        return result;
    }
    
};

int main(){
    Solution S;
    cout<<S.maxValue(6,2,931384943)<<endl;
}